package com.csy.commons.framework.service;

import com.csy.commons.dto.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

/**
 * 用户权限处理

 */
@Component
public class SysPermissionService {

    @Autowired
    private SysRoleService roleService;

    @Autowired
    private SysMenuService sysMenuService;

    /*
    * 获取角色数据权限
    * */
    public Set<String> getRolePermission(SysUser user){
        Set<String> roles = new HashSet<>();
        //是否有管理员权限
        if (user.isAdmin()){
            roles.add("admin");
        }else {
            roles = roleService.selectRolePermissionByUserId(user.getUserId());
        }
        return roles;
    }

    /*
     * 获取菜单数据权限
     * */
    public Set<String> getMenuPermission(SysUser user){
        Set<String> perms = new HashSet<>();
        //是否是管理员权限，如过是就拥有全部权限
        if (user.isAdmin()){
            perms.add("*:*:*");
        }else {
//            perms.add("*:*:*");
           perms = sysMenuService.selectMenuPermissionByUserId(user.getUserId());
        }
        return perms;
    }

}
